home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / Feelin021015 / Examples / Class1.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-28  |  3.7 KB  |  138 lines

  1. #include    <stdio.h>
  2.  
  3. #include    <clib/exec_protos.h>
  4. #include    <clib/dos_protos.h>
  5. #include    <clib/graphics_protos.h>
  6. #include    <clib/feelin_protos.h>
  7.  
  8. #include    <libraries/feelin.h>
  9.  
  10. struct FeelinBase *FeelinBase;
  11.  
  12. /// myAskMinMax
  13. __saveds ULONG myAskMinMax(struct FeelinClass *psClass,APTR Obj)
  14. {
  15. /*
  16.    FM_AskMinMax will be called before  the  window  is  opened  and  before
  17.    layout  takes place. We need to tell Feelin the minimum and maximum size
  18.    of our object.
  19. */
  20.    _minw(Obj) += 100 ; _maxw(Obj) = 500;
  21.    _minh(Obj) +=  40 ; _maxh(Obj) = 300;
  22.  
  23.    return F_SuperDo(psClass,Obj,FM_AskMinMax);
  24. }
  25. //+
  26. /// MyDraw
  27. __saveds ULONG myDraw(struct FeelinClass *psClass,APTR Obj,struct FS_Draw *d)
  28. {
  29.    ULONG i,c;
  30.    struct RastPort *rp;
  31.    UWORD x1,y1,x2,y2;
  32.  
  33.    /*
  34.       let our superclass draw itself first, Area class would e.g. draw  the
  35.       frame  and  clear  the  whole region. What it does exactly depends on
  36.       flags.
  37.    */
  38.  
  39.    F_SuperDoA(psClass,Obj,FM_Draw,(ULONG *) d);
  40.  
  41.    // Ok, everything ready to render...
  42.  
  43.    rp = _rp(Obj);
  44.    c  = FV_Pen_Shine;
  45.  
  46.    x1 = _mx(Obj); x2 = _mx2(Obj);
  47.    y1 = _my(Obj); y2 = _my2(Obj);
  48.  
  49.    for (i=x1 ; i<=x2 ; i+=5)
  50.    {
  51.       _APen(_pen(Obj,c));
  52.       _Move(x1,y2); _Draw( i,y1);
  53.       _Move(x2,y2); _Draw( i,y1);
  54.       c++; if (c == FV_Pen_Highlight) {c = FV_Pen_Shine;}
  55.    }
  56.  
  57.    return NULL;
  58. }
  59. //+
  60. /// myDispatcher
  61. /*
  62.    Here is the beginning of our simple new class...
  63.  
  64.    This is an example for the simplest possible  Feelin  class.  It's  just
  65.    some  kind  of  custom image and supports only two methods: FM_AskMinMax
  66.    and FM_Draw.
  67.  
  68.    This class is realy simple and do not requires any instance data.
  69. */
  70.  
  71. ULONG ASM SAVEDS myDispatcher(REG_A2 struct FeelinClass *psClass,REG_A0 APTR Obj,REG_D0 ULONG nMethod,REG_A1 ULONG *pnArgs)
  72. {
  73.  
  74. /*
  75.    Here comes the dispatcher for our custom class. We  only  need  to  care
  76.    about  FM_AskMinMax  and  FM_Draw  in  this  simple case. Unknown/unused
  77.    methods are passed to the superclass immediately.
  78. */
  79.     switch (nMethod)
  80.     {
  81.         case FM_AskMinMax : return myAskMinMax(psClass,Obj);
  82.         case FM_Draw      : return myDraw(psClass,Obj,(struct FS_Draw *)pnArgs);
  83.         default           : return F_SuperDoA(psClass,Obj,nMethod,pnArgs);
  84.     }
  85. }
  86. //+
  87.  
  88. /// Main
  89. void main()
  90. {
  91.    APTR c,w;
  92.    struct FeelinClass *fcc;
  93.    UBYTE inner[] = {4,2,4,2};
  94.  
  95.    if (FeelinBase = (struct FeelinBase *)OpenLibrary("feelin.library",FV_VERSION))
  96.    {
  97.       if (fcc = F_CreateClass(FA_SuperID,    FC_Area,
  98.                               FA_Dispatcher, myDispatcher,
  99.                               TAG_DONE))
  100.       {
  101.  
  102.          c = ClientObject,
  103.             FA_Client_Title,       "Class1",
  104.             FA_Client_Version,     "$VER: Class1 1.00 (03-08-02)",
  105.             FA_Client_Copyright,   "©2002, Olivier Laviale",
  106.             FA_Client_Author,      "Olivier Laviale (lotan9@aol.com)",
  107.             FA_Client_Description, "Demonstrate the use of custom classes.",
  108.             FA_Client_Base,        "CLASS1",
  109.  
  110.             Child, w = WindowObject,
  111.                FA_ID,           MAKE_ID('M','A','I','N'),
  112.                FA_Window_Title, "A Simple Custom Class",
  113.  
  114.                Child, F_NewObj(fcc->ID,TextFrame, TextBack, FA_Inner,inner, TAG_DONE),
  115.             End,
  116.          End;
  117.  
  118.          if (c) {
  119.             F_Do(w,FM_Notify,FA_Window_CloseRequest,TRUE,FV_Notify_Client,2,FM_Client_ReturnID,FV_Client_Quit);
  120.             F_Set(w,FA_Window_Open,TRUE);
  121.  
  122.             F_DoA(c,FM_Client_Run,NULL);
  123.  
  124.             F_DisposeObj(c);
  125.          }
  126.  
  127.          F_RemoveClass(fcc);
  128.       } else {
  129.          Printf("Unable to create custom class\n");
  130.       }
  131.  
  132.       CloseLibrary((struct Library *)FeelinBase);
  133.    } else {
  134.       Printf("Unable to open feelin.library\n");
  135.    }
  136. }
  137. //+
  138.